<?php
/*
* LoginModel.php
* Contains functions to execute on the database and login the user.
*/
class LoginModel
{
	/**
	* LoginUser
	* Authenticate/login the user.
	*
	* @param strnig $username The username to login.
	* @param string $password The matching password (to the username).
	*
	* @return bool True if the username and password match in the database.
	*			False is the username and password don't match in the database
				or if the user doesn't exist.
	*/
	public function LoginUser( $username, $password )
	{
		require_once Settings::DBPath();
		$DB = new Database();
		
		if ( $DB->Connect() )
		{	
			$statement = $DB->Prepare( "SELECT username, password FROM users WHERE username=? AND password=?" );
			$statement->bind_param( "ss", $username, $password );
			$statement->execute();
			$statement->bind_result( $row_username, $row_password );
			
			if ( $statement->fetch() )
			{
				return true;
			}
		}
		return false;
	}
}